#include <StateManager>
#include <State>

StateManager::StateManager(QObject *parent)
    : QObject(parent)
{
}

void StateManager::setCurrentState(QPointer<State> state)
{
    if(m_currentState == state) return;

    if(m_currentState)
    {
        m_currentState->exit();
        emit stateExited(m_currentState);
    }

    m_currentState = state;
    m_currentState->enter();
    emit stateEntered(m_currentState);
}

void StateManager::handleMousePressEvent(QMouseEvent *pEvent)
{
    if(m_currentState)
    {
        m_currentState->onMousePress(pEvent);
    }
}

void StateManager::handleMouseMoveEvent(QMouseEvent *pEvent)
{
    if(m_currentState)
    {
        m_currentState->onMouseMove(pEvent);
    }
}

void StateManager::handleMouseReleaseEvent(QMouseEvent *pEvent)
{
    if(m_currentState)
    {
        m_currentState->onMouseRelease(pEvent);
    }
}

void StateManager::handleDraw()
{
    if(m_currentState)
    {
        m_currentState->draw();
    }
}
